﻿using GraphQL.Types;
using GraphQLSample.Domain.Core;
using GraphQLSample.Domain.Services;
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphQLSample.Domain.Schema
{
    public class UserMutation
        : ObjectGraphType
    {
        public UserMutation(IUserService userService)
        {
            Name = "Mutation";
            Description = string.Empty;

            Field<BooleanGraphType>("createUser", 
                arguments: new QueryArguments(new QueryArgument(typeof(NonNullGraphType<UserInputType>)) { Name = "input" }),
                resolve: context =>
                {
                    var args = context.GetArgument<UserInputDto>("input");
                    var name = args.Name;
                    return userService.CreateUser(name);
                });
        }
    }
}
